using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace Rensselaer_Event_Finder
{
    public partial class RSVPMDI : Form
    {

        #region Constructor

        public RSVPMDI()
        {
            InitializeComponent();
        }

        #endregion

        #region Form Events

        private void RSVPMDI_Load(object sender, EventArgs e)
        {

        }

        private void homeBtn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MainForm.SelectMDIForm(MainForm.homeFrm);
        }

        //remove from rsvp
        void NotAttenting_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            Panel addedPanel = (Panel)btn.Tag;
            Event removeEvt = Globals.getEventService().getById((int)addedPanel.Tag);
            Globals.CurrentUser.Events.Remove(removeEvt);
            flowLayoutPanel1.Controls.Remove(addedPanel);
        }
 
        // link to website
        void WebsiteLink_Click(object sender, EventArgs e)
        {
            string url = ((LinkLabel)sender).Text;
            if (!url.StartsWith("www."))
            {
                url = "www." + url;
            }
            System.Diagnostics.Process.Start(url);
        }

        // link to venue
        void VenueLink_Click(object sender, EventArgs e)
        {
            //load the venue corresponding to the id in the tag, show that venue in the VenueMDI
            LinkLabel senderLink = (LinkLabel)sender;
            Location loadLoc = Globals.getLocationService().getById((int)senderLink.Tag);
            MainForm.venueFrm.load_venue(loadLoc);
            MainForm.SelectMDIForm(MainForm.venueFrm);
        }

        //link to event
        void EventName_Click(object sender, EventArgs e)
        {
            //load the venue corresponding to the id in the tag, show that venue in the VenueMDI
            LinkLabel senderLink = (LinkLabel)sender;
            Location loadLoc = Globals.getLocationService().getById((int)senderLink.Tag);
            MainForm.venueFrm.load_venue(loadLoc);
            MainForm.SelectMDIForm(MainForm.venueFrm);
        }

        #endregion

        #region Private Methods

        //add event user has rsvp'ed for
        private void addMyEvent(Event Evt)
        {

            System.Windows.Forms.Button NotAttenting;
            System.Windows.Forms.Panel panel1;
            System.Windows.Forms.PictureBox EventPic;
            System.Windows.Forms.Label label2;
            System.Windows.Forms.Label label3;
            System.Windows.Forms.LinkLabel VenueLink;
            System.Windows.Forms.Label label5;
            System.Windows.Forms.LinkLabel WebsiteLink;
            System.Windows.Forms.Label PriceLbl;
            System.Windows.Forms.Label EndTimeLabel;
            System.Windows.Forms.Label StartTimeLabel;
            System.Windows.Forms.LinkLabel EventName;
            System.Windows.Forms.Label PriceLabel;


            NotAttenting = new System.Windows.Forms.Button();
            panel1 = new System.Windows.Forms.Panel();
            EventPic = new System.Windows.Forms.PictureBox();
            label2 = new System.Windows.Forms.Label();
            VenueLink = new System.Windows.Forms.LinkLabel();
            label3 = new System.Windows.Forms.Label();
            PriceLbl = new System.Windows.Forms.Label();
            WebsiteLink = new System.Windows.Forms.LinkLabel();
            label5 = new System.Windows.Forms.Label();
            PriceLabel = new System.Windows.Forms.Label();
            EventName = new System.Windows.Forms.LinkLabel();
            StartTimeLabel = new System.Windows.Forms.Label();
            EndTimeLabel = new System.Windows.Forms.Label();
            panel1.SuspendLayout();

            //
            // NotAttenting
            // 
            NotAttenting.BackColor = System.Drawing.Color.DarkGray;
            NotAttenting.FlatStyle = System.Windows.Forms.FlatStyle.System;
            NotAttenting.ForeColor = System.Drawing.Color.Black;
            NotAttenting.Location = new System.Drawing.Point(655, 22);
            NotAttenting.Name = "NotAttenting";
            NotAttenting.Size = new System.Drawing.Size(82, 23);
            NotAttenting.TabIndex = 2;
            NotAttenting.Text = "Not Attending";
            NotAttenting.UseVisualStyleBackColor = false;
            NotAttenting.Tag = panel1;
            NotAttenting.Click += new EventHandler(NotAttenting_Click);
            // 
            // panel1
            // 
            panel1.BackColor = System.Drawing.Color.Black;
            panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            panel1.Controls.Add(EndTimeLabel);
            panel1.Controls.Add(StartTimeLabel);
            panel1.Controls.Add(EventName);
            panel1.Controls.Add(PriceLabel);
            panel1.Controls.Add(label5);
            panel1.Controls.Add(WebsiteLink);
            panel1.Controls.Add(PriceLbl);
            panel1.Controls.Add(label3);
            panel1.Controls.Add(VenueLink);
            panel1.Controls.Add(label2);
            panel1.Controls.Add(EventPic);
            panel1.Controls.Add(NotAttenting);
            panel1.ForeColor = System.Drawing.Color.White;
            panel1.Location = new System.Drawing.Point(3, 3);
            panel1.Name = "panel1";
            panel1.Size = new System.Drawing.Size(791, 150);
            panel1.TabIndex = 4;
            panel1.Tag = Evt.Id;
            // 
            // EventPic
            // 
            EventPic.BackColor = System.Drawing.Color.Black;
            EventPic.Location = new System.Drawing.Point(16, 14);
            EventPic.Name = "EventPic";
            EventPic.Size = new System.Drawing.Size(123, 123);
            EventPic.TabIndex = 4;
            EventPic.TabStop = false;
            EventPic.SizeMode = PictureBoxSizeMode.StretchImage;
            //
            if (Evt.Image_url != "" && Evt.Image_url != null)
            {
                EventPic.Image = Globals.loadImageFromURL(Evt.Image_url);
            }
            else
            {
                EventPic.Image = Globals.loadImageFromURL(Evt.Location.Image_url);
            }
            // 
            // label2
            // 
            label2.AutoSize = true;
            label2.BackColor = System.Drawing.Color.Black;
            label2.ForeColor = System.Drawing.Color.White;
            label2.Location = new System.Drawing.Point(409, 70);
            label2.Name = "label2";
            label2.Size = new System.Drawing.Size(58, 13);
            label2.TabIndex = 5;
            label2.Text = "Start Time:";
            // 
            // VenueLink
            // 
            VenueLink.AutoSize = true;
            VenueLink.BackColor = System.Drawing.Color.Black;
            VenueLink.ForeColor = System.Drawing.Color.White;
            VenueLink.LinkColor = System.Drawing.Color.White;
            VenueLink.Location = new System.Drawing.Point(159, 70);
            VenueLink.Name = "VenueLink";
            VenueLink.Size = new System.Drawing.Size(61, 13);
            VenueLink.TabIndex = 6;
            VenueLink.TabStop = true;
            VenueLink.Text = Evt.Location.Name;
            VenueLink.Tag = Evt.Location.Id;
            VenueLink.Click += new EventHandler(VenueLink_Click);
            // 
            // label3
            // 
            label3.AutoSize = true;
            label3.BackColor = System.Drawing.Color.Black;
            label3.ForeColor = System.Drawing.Color.White;
            label3.Location = new System.Drawing.Point(409, 92);
            label3.Name = "label3";
            label3.Size = new System.Drawing.Size(55, 13);
            label3.TabIndex = 7;
            label3.Text = "End Time:";
            // 
            // PriceLbl
            // 
            PriceLbl.AutoSize = true;
            PriceLbl.BackColor = System.Drawing.Color.Black;
            PriceLbl.ForeColor = System.Drawing.Color.White;
            PriceLbl.Location = new System.Drawing.Point(159, 114);
            PriceLbl.Name = "Description";
            PriceLbl.Size = new System.Drawing.Size(60, 13);
            PriceLbl.TabIndex = 8;
            PriceLbl.Text = Evt.Price;
            // 
            // WebsiteLink
            // 
            WebsiteLink.AutoSize = true;
            WebsiteLink.BackColor = System.Drawing.Color.Black;
            WebsiteLink.ForeColor = System.Drawing.Color.White;
            WebsiteLink.LinkColor = System.Drawing.Color.White;
            WebsiteLink.Location = new System.Drawing.Point(159, 45);
            WebsiteLink.Name = "WebsiteLink";
            WebsiteLink.Size = new System.Drawing.Size(69, 13);
            WebsiteLink.TabIndex = 9;
            WebsiteLink.TabStop = true;
            WebsiteLink.Click += new EventHandler(WebsiteLink_Click);
            WebsiteLink.Text = Evt.Website;
            //Only make it a link if it contains a website
            if (Evt.Website != null && Evt.Website != "")
            {
                WebsiteLink.Text = Evt.Website;
                WebsiteLink.Enabled = true;
            }
            else
            {
                WebsiteLink.Text = "N/A";
                WebsiteLink.Enabled = false;
            }
            // 
            // label5
            // 
            label5.AutoSize = true;
            label5.BackColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.White;
            label5.Location = new System.Drawing.Point(159, 92);
            label5.Name = "label5";
            label5.Size = new System.Drawing.Size(34, 13);
            label5.TabIndex = 10;
            label5.Text = "Price:";
            // 
            // PriceLabel
            // 
            PriceLabel.AutoSize = true;
            PriceLabel.BackColor = System.Drawing.Color.Black;
            PriceLabel.ForeColor = System.Drawing.Color.White;
            PriceLabel.Location = new System.Drawing.Point(199, 92);
            PriceLabel.Name = "PriceLabel";
            PriceLabel.Size = new System.Drawing.Size(60, 13);
            PriceLabel.TabIndex = 11;
            //PriceLabel.Text = Evt.Price;
            // 
            // EventName
            // 
            EventName.AutoSize = true;
            EventName.BackColor = System.Drawing.Color.Black;
            EventName.ForeColor = System.Drawing.Color.White;
            EventName.LinkColor = System.Drawing.Color.White;
            EventName.Location = new System.Drawing.Point(159, 22);
            EventName.Name = "EventName";
            EventName.Size = new System.Drawing.Size(66, 13);
            EventName.TabIndex = 12;
            EventName.TabStop = true;
            EventName.Text = Evt.Name;
            EventName.Tag = Evt.Location.Id;
            EventName.Click += new EventHandler(EventName_Click);
            // 
            // StartTimeLabel
            // 
            StartTimeLabel.AutoSize = true;
            StartTimeLabel.BackColor = System.Drawing.Color.Black;
            StartTimeLabel.ForeColor = System.Drawing.Color.White;
            StartTimeLabel.Location = new System.Drawing.Point(474, 70);
            StartTimeLabel.Name = "StartTimeLabel";
            StartTimeLabel.Size = new System.Drawing.Size(80, 13);
            StartTimeLabel.TabIndex = 13;
            StartTimeLabel.Text = Evt.StartTime.ToShortDateString() + " " + Evt.StartTime.ToShortTimeString();
            // 
            // EndTimeLabel
            // 
            EndTimeLabel.AutoSize = true;
            EndTimeLabel.BackColor = System.Drawing.Color.Black;
            EndTimeLabel.ForeColor = System.Drawing.Color.White;
            EndTimeLabel.Location = new System.Drawing.Point(474, 92);
            EndTimeLabel.Name = "EndTimeLabel";
            EndTimeLabel.Size = new System.Drawing.Size(81, 13);
            EndTimeLabel.TabIndex = 14;
            EndTimeLabel.Text = Evt.EndTime.ToShortDateString() + " " + Evt.EndTime.ToShortTimeString();

            flowLayoutPanel1.Controls.Add(panel1);
        }

        public void clearEvents()
        {
            flowLayoutPanel1.Controls.Clear();
        }

        public void LoadEvents()
        {
            if (Globals.CurrentUser == null)
            {
                MessageBox.Show("Must login first...", "Error");
            }
            else
            {
                foreach (Event evt in Globals.CurrentUser.Events)
                {
                    addMyEvent(evt);
                }
            }
        }

        #endregion

    }
}